#ifndef POLYGONENTITY_H
#define POLYGONENTITY_H

#include "Common/Common.h"
#include "EditorCore/IProvider.h"
#include "EditorCore/Entity.h"
#include "Entities/VertexEntity.h"

class BodyEntity;

class PolygonEntity : public editor_core::Entity, public editor_core::IProvider<PolygonEntity*>
{
public:
	PolygonEntity( BodyEntity* parentBody, const cmn::Transform& position );
	virtual ~PolygonEntity();

	inline cmn::Transform GetPosition() const { return m_position; }
	inline void SetPosition( cmn::Transform position ) { m_position = position; }

	void AddVertex( VertexEntity* vertex );
	void RemoveVertex( VertexEntity* vertex );
	void GetVertices( cmn::ICollection<VertexEntity*>& vertices ) const;

	virtual inline PolygonEntity* GetEntity() { return this; }

	virtual void Tick();

	virtual cmn::Vec2 Move( const cmn::Vec2& vector );

	virtual void Delete();
	virtual void Undelete();

	virtual bool Contains( const cmn::Vec2& point ) const;

	virtual void GetChildren( cmn::ICollection<IEntity*>& children ) const;
	virtual void GetParents( cmn::ICollection<IEntity*>& parents ) const;

	virtual void GetProperties( cmn::ICollection<editor_core::Property>& properties ) const;
	virtual bool TryUpdateProperty( editor_core::Property& property ) const;
	virtual bool TryUpdateFromProperty( const editor_core::Property& property );

protected:
	virtual void DrawInner( drawing::IDrawer* drawer );

private:
	cmn::Transform m_position;

	BodyEntity* m_parentBody;
	cmn::Vector<VertexEntity*> m_childrenVertices;
};

#endif
